package bookStore.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bookStore.service.business.AuthorService;
import bookStore.service.business.AuthorServiceImpl;
import bookStore.service.business.BookService;
import bookStore.service.business.BookServiceImpl;
import bookStore.service.business.ReviewService;
import bookStore.service.business.ReviewServiceImpl;
import bookStore.tool.Constants;
import bookStore.tool.UrlUtil;
import bookStore.vo.AuthorVo;
import bookStore.vo.BookVo;
import bookStore.vo.BookWithPicture;

/**
 * Servlet implementation class AuthorController
 */
@WebServlet("/author/*")
public class AuthorController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String url;
	private String traget="";
	private ReviewService reviewService = new ReviewServiceImpl();
	private AuthorService authorService = new AuthorServiceImpl();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AuthorController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		url = UrlUtil.getUrl(request.getRequestURI());
		switch(url) {
			
			case "detail":
				int authorId = Integer.parseInt(request.getParameter("authorId"));
				AuthorVo authorVo = authorService.getAuthorVoById(authorId);
				request.setAttribute("author", authorVo);
				setTraget("/WEB-INF/business/author/item.jsp");
				
				break;

		}
		
		if(traget.endsWith(".jsp")) {
			request.getRequestDispatcher(traget).forward(request, response);
		}else {
			response.sendRedirect(traget);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

	public String getTraget() {
		return traget;
	}

	public void setTraget(String traget) {
		this.traget = traget;
	}
	
	

}
